package com.candy.databasedocuments.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * @author suYanLong
 * @date 2022年10月13日 11:48
 */
@Configuration
public class ApplicationContentUtils implements ApplicationContextAware, DisposableBean {

    private Logger logger = LoggerFactory.getLogger(ApplicationContentUtils.class);

    public static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static <T> T getBean(Class<T> var1) {
        return getApplicationContext().getBean(var1);
    }

    @Override
    public void destroy() throws Exception {
        logger.info("容器关闭");
    }

}
